package org.dromara.hm.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.hm.domain.vo.HmStockChangeVo;
import org.dromara.hm.domain.bo.HmStockChangeBo;
import org.dromara.hm.service.IHmStockChangeService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 库存变更明细
 *
 * @author hzy
 * @date 2025-04-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hm/stockChange")
public class HmStockChangeController extends BaseController {

    private final IHmStockChangeService hmStockChangeService;

    /**
     * 查询库存变更明细列表
     */
 //   @SaCheckPermission("hm:stockChange:list")
    @GetMapping("/list")
    public TableDataInfo<HmStockChangeVo> list(HmStockChangeBo bo, PageQuery pageQuery) {
        return hmStockChangeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出库存变更明细列表
     */
  //  @SaCheckPermission("hm:stockChange:export")
    @Log(title = "库存变更明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HmStockChangeBo bo, HttpServletResponse response) {
        List<HmStockChangeVo> list = hmStockChangeService.queryList(bo);
        ExcelUtil.exportExcel(list, "库存变更明细", HmStockChangeVo.class, response);
    }

    /**
     * 获取库存变更明细详细信息
     *
     * @param changeId 主键
     */
  //  @SaCheckPermission("hm:stockChange:query")
    @GetMapping("/{changeId}")
    public R<HmStockChangeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long changeId) {
        return R.ok(hmStockChangeService.queryById(changeId));
    }

    /**
     * 新增库存变更明细
     */
   // @SaCheckPermission("hm:stockChange:add")
    @Log(title = "库存变更明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HmStockChangeBo bo) {
        return toAjax(hmStockChangeService.insertByBo(bo));
    }

    /**
     * 修改库存变更明细
     */
   // @SaCheckPermission("hm:stockChange:edit")
    @Log(title = "库存变更明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HmStockChangeBo bo) {
        return toAjax(hmStockChangeService.updateByBo(bo));
    }

    /**
     * 删除库存变更明细
     *
     * @param changeIds 主键串
     */
//    @SaCheckPermission("hm:stockChange:remove")
    @Log(title = "库存变更明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{changeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] changeIds) {
        return toAjax(hmStockChangeService.deleteWithValidByIds(List.of(changeIds), true));
    }
}
